package com.kgcx.schedule.service;

import com.kgcx.dbutils.core.mapper.BaseMapper;
import com.kgcx.dbutils.core.model.ParameterMap;
import com.kgcx.dbutils.core.model.RowMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public abstract class BaseBusinessService<P, E> {
    protected Logger log = LoggerFactory.getLogger(BaseBusinessService.class);

    protected abstract BaseMapper<P, E> getMapper();

    // @Transactional(readOnly = true)
    public E selectEntity(P primaryKey) {
        return getMapper().selectEntity(primaryKey);
    }

    // @Transactional(readOnly = true)
    public List<E> selectEntityListPage(ParameterMap params) {
        return getMapper().selectEntityListPage(params);
    }

    // @Transactional(readOnly = true)
    public List<RowMap> selectMapEntityListPage(ParameterMap params) {
        return getMapper().selectMapEntityListPage(params);
    }

    @Transactional(rollbackFor = Exception.class)
    public void insertEntity(E entity) {
        getMapper().insertEntity(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    public void insertEntities(List<E> entityList) {
        getMapper().insertEntities(entityList);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateEntity(E entity) {
        getMapper().updateEntity(entity);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteEntity(P primaryKey) {
        getMapper().deleteEntity(primaryKey);
    }

    @Transactional(rollbackFor = Exception.class)
    public void deleteEntities(ParameterMap params) {
        getMapper().deleteEntities(params);
    }
}
